home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Workbench / Archive / XPK / xpk_Source / test / testFHUnpack.c < prev    next >
C/C++ Source or Header  |  1998-11-15  |  1KB  |  71 lines

  1. #define NAME        "testFHUnpack"
  2. #define DISTRIBUTION    "(Freeware) "
  3. #define REVISION    "1"
  4. #define SDI_ENDCODE_NOCTRLC
  5.  
  6. /* Programmheader
  7.  
  8.     Name:        testFHUnpack
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    easy file to file unpacker using FH's
  12.     Compileropts:    -
  13.     Linkeropts:    -l xpkmaster amiga
  14.  
  15.  1.0   02.04.97 : first version
  16.  1.1   28.11.97 : moved chunk-hook into include file
  17. */
  18.  
  19. /* NOTE: You may pass option OFFSET, when packed data does not start at
  20.    really file start */
  21.  
  22. #include <proto/exec.h>
  23. #include <proto/dos.h>
  24. #include <proto/xpkmaster.h>
  25. #include "SDI_defines.h"
  26. #include "chunkhook.c"
  27.  
  28. struct Library        *XpkBase    = 0;
  29. ULONG            DosVersion    = 37;
  30. struct RDArgs        *rda        = 0;
  31. ULONG            fhin        = 0;
  32. ULONG            fhout        = 0;
  33.  
  34. #define PARAM "FROM/A,TO/A,OFFSET/K/N"
  35.  
  36. void main(void)
  37. {
  38.   ULONG err;
  39.  
  40.   struct {
  41.     STRPTR from;
  42.     STRPTR to;
  43.     ULONG  *offset;
  44.   } args = {0, 0, 0};
  45.  
  46.   if(!(rda = ReadArgs(PARAM, (LONG *) &args, 0)) ||
  47.   !(XpkBase = OpenLibrary(XPKNAME, 4)) ||
  48.   !(fhin = Open(args.from, MODE_OLDFILE)) ||
  49.   !(fhout = Open(args.to, MODE_NEWFILE)) ||
  50.   (args.offset && Seek(fhin, *args.offset, OFFSET_BEGINNING) == -1))
  51.     End(RETURN_FAIL);
  52.  
  53.   if((err = XpkUnpackTags(XPK_InFH, fhin, XPK_OutFH, fhout,
  54.   XPK_ChunkHook, &chunkhook, TAG_DONE)))
  55.   {
  56.     XpkPrintFault(err, "Can't XpkUnpack");
  57.     End(RETURN_FAIL);
  58.   }
  59.  
  60.   End(RETURN_OK);
  61. }
  62.  
  63. void end(void)
  64. {
  65.   if(fhout)    Close(fhout);
  66.   if(fhin)    Close(fhin);
  67.   if(XpkBase)    CloseLibrary(XpkBase);
  68.   if(rda)    FreeArgs(rda);
  69. }
  70.  
  71.